package com.crthread;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Date;
import java.util.Scanner;

public class ThreadOne extends Thread {
    private String threadName ;
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    public ThreadOne(String threadName) {
        this.threadName = threadName;
    }

    @Override
    public void run() {
        int i = 0 ;
        while (true){

            i++;
            logger.info(String.format("时间:%s,少女:%s,编号 :%s",new Date(),this.threadName,i));
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        while (true){
            System.out.println("输入少女线程:");
            Scanner scanner =  new Scanner(System.in);
            String str = scanner.next();
            if(str.equals("stop")){
                scanner.close();
                Thread.interrupted();

               break;
            }
            ThreadOne threadOne = new ThreadOne(str);
            threadOne.start();
            while (threadOne.isAlive()){
                threadOne.interrupt();
            }
        }
    }
}
